<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%">
    <el-col><span>{{ treeNode.name }}</span></el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addFn(treeNode)">添加子部门</el-dropdown-item>
              <!-- 编辑和删除部门只在子部门上显示 -->
              <el-dropdown-item v-if="!isRoot" @click.native="editFn(treeNode)">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delFn(treeNode.id)">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'
export default {
  props: {
    treeNode: {
      type: Object, // 对象类型
      required: true // 要求对方使用您的组件的时候 必须传treeNode属性 如果不传 就会报错
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    async delFn(id) {
      // console.log(id)
      // console.log(res)
      await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      await delDepartment(id)
      this.$message.success('删除成功')
      this.$emit('delDepartment')
    },
    async addFn(treeNode) {
      this.$emit('showDialog', treeNode)
    },
    editFn(treeNode) {
      this.$emit('editDepts', treeNode)
    }
  }
}
</script>

<style>

</style>
